package com.teangtang.fly.controller;

import com.teangtang.fly.dto.TicketDTO;
import com.teangtang.fly.entity.Ticket;
import com.teangtang.fly.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;

@RestController
@RequestMapping("/tickets")
public class TicketController {

    @Autowired
    private TicketService ticketService;

    @GetMapping
    public Page<TicketDTO> searchTickets(
            @RequestParam(value = "id", required = false) String id,
            @RequestParam(value = "flightId", required = false) String flightId,
            @RequestParam(value = "idCard", required = false) String idCard,
            Pageable pageable) {
        return ticketService.searchTickets(id, flightId, idCard, pageable);
    }

    @GetMapping("/{id}")
    public Ticket getTicketById(@PathVariable Long id) {
        return ticketService.getTicketById(id);
    }

    @PostMapping
    public boolean updateTicket(@RequestBody TicketDTO ticketDTO) {
        return ticketService.updateTicket(ticketDTO,0);
    }
    @PostMapping("/status")
    public boolean updateTicketStatus(@RequestBody TicketDTO ticketDTO) {
        return ticketService.updateTicket(ticketDTO,1);
    }
    @DeleteMapping("/{id}")
    public void deleteTicket(@PathVariable Long id) {
        ticketService.deleteTicket(id);
    }
}
